# This module compiles the code in src (the directory next
# to the top-level CMakeLists.txt file).
#
# Currently using a simplified build scheme where, every
# directory under src is included. A g++ equiviliant, in
# sudo code would be "-I/src/* --recurse".
#
# Also, every cpp file will be added in blindly. If this 
# project had multiple components (such as shared libraries
# or utilities), then this approach would probably not be
# ideal. However, I expect the project to be minimal.
#
# If the project grows in complexity, then we can use
# components.
#
# Jeff Wicks - Thursday, December 26, 2013

MESSAGE("+++ Started: CompileSoftware +++") 


# Build a list of all cpp files under ~/src
FILE(GLOB_RECURSE cpp_files ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
 

# For each cpp file found, add its dirname (path) to ${source_directories}
# If there is more than one cpp file in a directory, then the directory will
# will be added more than once. I think that is not a problem.
MESSAGE("\nAdding the following files (as well as their dirnames) to the project:") 
  FOREACH(cpp_file ${cpp_files})
    MESSAGE("${cpp_file}") 
    GET_FILENAME_COMPONENT(directory_to_include ${cpp_file} PATH) 	# Extract the dirname
    LIST(APPEND source_directories ${directory_to_include})		# and add it to a list
ENDFOREACH()

INCLUDE_DIRECTORIES(${source_directories}
${Wt_INCLUDE_DIR})

# Make the binary go into bin. For testing, I can copy resource files there.
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# # Assemble the executable.
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}
    ${cpp_files})

FIND_PACKAGE(Wt 3.2.1 REQUIRED)

# Boost signals are used for the signal/slot mechansim. Lambdas can also be used for small functions (that
# are good inline candidates).
# NOTE: "Boost.Signals is no longer being maintained and is now deprecated. Please switch to Boost.Signals2. To disable this warning message, define BOOST_SIGNALS_NO_DEPRECATION_WARNING."
FIND_PACKAGE(Boost 1.46.0 REQUIRED COMPONENTS signals)
IF(NOT Boost_FOUND)
  MESSAGE(FATAL_ERROR "Possible solution: On Debian 7 run `apt-get install libboost-signals-dev`")
ENDIF()

# Link the executable.
TARGET_LINK_LIBRARIES(${CMAKE_PROJECT_NAME}
  ${Boost_LIBRARIES}
  wthttp
  wt)
